<template>
  <div class="page-container">
    <!--工具栏-->
    <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
      <el-form :inline="true" :model="filters" :size="size" ref="filters">
        <el-form-item prop="shopname">
          <el-input v-model="filters.shopname" placeholder="店铺名称"></el-input>
        </el-form-item>
        <el-form-item prop="productname">
          <el-input v-model="filters.productname" placeholder="商品名称"></el-input>
        </el-form-item>
        <el-form-item prop="assemblesort">
           <el-select v-model="filters.assemblesort" placeholder="拼团分类">
                <el-option
                v-for="item in assemblesorts"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item prop="isjingxuan">
           <el-select v-model="filters.isjingxuan" placeholder="精选">
                <el-option
                v-for="item in isjingxuans"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item prop="startDate">
            <el-date-picker
                v-model="filters.startDate"
                type="date"
                value-format="yyyy-MM-dd"
                format="yyyy-MM-dd"
                placeholder="开始时间" class="input_postion">
            </el-date-picker>
        </el-form-item>
        <el-form-item prop="endDate">
            <el-date-picker
                v-model="filters.endDate"
                type="date"
                value-format="yyyy-MM-dd"
                format="yyyy-MM-dd"
                placeholder="结束时间" class="input_postion">
            </el-date-picker>
        </el-form-item>
        <el-row>
          <el-form-item>
            <kt-button
              icon="fa fa-search"
              :label="$t('action.search')"
              type="primary"
              @click="findPage(null)"
            />
          </el-form-item>
          <el-form-item>
            <kt-button icon="fa fa-refresh" :label="$t('action.reset')" type="primary" @click="resetForm('filters')" />
          </el-form-item>
          <el-form-item>
            <kt-button label="设置精选" type="primary" @click="editButton" />
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
      <el-form :inline="true" :size="size">
        <el-form-item>
          <el-button-group>
            <el-tooltip content="刷新" placement="top">
              <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
            </el-tooltip>
            <el-tooltip content="列显示" placement="top">
              <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
            </el-tooltip>
            <el-tooltip content="导出" placement="top">
              <el-button icon="fa fa-file-excel-o" @click="downloadExcel"></el-button>
            </el-tooltip>
          </el-button-group>
        </el-form-item>
      </el-form>
      <!--表格显示列界面-->
      <table-column-filter-dialog
        ref="tableColumnFilterDialog"
        :columns="columns"
        @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>
    </div>
    <!--表格内容栏-->
    <cy-table
      :height="350"
      permsDelete="false"
      :data="pageResult"
      :columns="filterColumns"
      :showEditOperation="false"
      :showDetailOperation="true"
      :showBatchDelete="true"
      :showOperation="true"
      :showDeleteOperation="false"
      @findPage="findPage"
      @handleDetail="handleDetail"
      @selectionChange="selectionChange"
      ref="CyTable"
    ></cy-table>
    <el-dialog
      title="出库明细"
      width="43%"
      :visible.sync="dialogVisible"
      :close-on-click-modal="true"
      @closed="closeDetail"
    >
      <el-table
        style="width: 100%"
        :close-on-click-modal="true"
        :data="tableData"
        :columns="filterColumns"
        @closed="closeDetail"
      >
        <el-table-column fixed prop="skunumber" label="SKU编码" width="150"></el-table-column>
        <el-table-column prop="productname" label="商品名称" width="150"></el-table-column>
        <el-table-column prop="specs" label="规格" width="150"></el-table-column>
        <el-table-column prop="marketprice" label="市场价" width="150"></el-table-column>
        <el-table-column prop="type" label="分类" width="150"></el-table-column>
        <el-table-column prop="brand" label="品牌" width="150"></el-table-column>
        <el-table-column prop="price" label="单价" width="150"></el-table-column>
        <el-table-column prop="shopname" label="店铺名称" width="150"></el-table-column>
      </el-table>

      <!--分页栏-->
      <div class="toolbar" style="padding:10px;">
        <el-pagination
          layout="total, sizes, prev, pager, next, jumper"
          @current-change="refreshPageRequest"
          @size-change="handleSizeChange"
          :current-page="pageRequest.pageNum"
          :page-size="pageRequest.pageSize"
          :total="totalSize"
          style="float:right;"
          :page-sizes="[10, 20, 30, 40]"
        ></el-pagination>
      </div> 
    </el-dialog>
  </div>
</template>

<script>
import CyTable from "@/views/Core/CyTable";
import KtButton from "@/views/Core/KtButton";
import { format } from "@/utils/datetime";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
export default {
  components: {
    CyTable,
    KtButton,
    TableColumnFilterDialog
  },
  data() {
    return {
      size: "small",
      filters: {
        shopname: "",
        productname: "",
        isjingxuan: "",
        assemblesort: "",
        startTime: "",
        endTime: "",
        t: "marketAssemble"
      },
      assemblesorts: [{'value':'','label':'请选择'},{'value':'实物类商品','label':'实物类商品'},{'value':'虚拟类商品','label':'虚拟类商品'}],
      isjingxuans: [{'value':'','label':'请选择'},{'value':'0','label':'是'},{'value':'1','label':'否'}],
      statusOption: [{
        status: '',
        label: '请选择'
      }, {
        status: 'N',
        label: '可用'
      }, {
        status: 'Y',
        label: '不可用'
      }],
      tableData: [],
      detailParam: {},
      totalSize:0,
      operation: false, // true:新增, false:编辑
      dialogVisible: false, // 新增编辑界面是否显示
      columns: [
        { prop: "id", label: "编号", minWidth: 100},
        { prop: "shopname", label: "店铺名称", minWidth: 100},
        { prop: "productname", label: "商品名称", minWidth: 100 },
        { prop: "assemblesort", label: "拼团分类", minWidth: 80 },
        { prop: "assemblenumber", label: "拼团人数", minWidth: 120},
        { prop: "assembleover", label: "已成团", minWidth: 120 },
        { prop: "assembleoprice", label: "拼团价", minWidth: 100 },
        { prop: "isjingxuan", label: "是否精选", minWidth: 100 ,formatter: this.showJinXuanType},
        { prop: "starttime", label: "活动开始时间", minWidth: 100 },
        { prop: "endtime", label: "活动结束时间", minWidth: 100 },
        { prop: "status", label: "状态", minWidth: 100 ,formatter: this.showStatusType},
        { prop: "platformsort", label: "平台专用分类", minWidth: 100 ,formatter: this.showPlatformSortType}
	  ],
	  filterColumns:[],
      pageRequest: { pageNum: 1, pageSize: 10 },
      pageResult: {},

      operation: false, // true:新增, false:编辑
      editDialogVisible: false, // 新增编辑界面是否显示
      editLoading: false,
    };
  },
  methods: {
    // 获取分页数据
    findPage: function(data) {
      this.$refs.CyTable.findPage(this.filters);
    },
    showJinXuanType(row, column, cellValue, index) {
        if (row.isjingxuan==0) {
          return '是';
        }else if(row.isjingxuan==1) {
          return '否';
        }
    },
    showStatusType(row, column, cellValue, index) {
        if (row.status==0) {
          return '未开始';
        }else if(row.status==1) {
          return '进行中';
        }else{
            return '已结束';
        }
    },
    showPlatformSortType(row, column, cellValue, index) {
        if (row.platformsort==0) {
          return '是';
        }else if(row.platformsort==1) {
          return '否';
        }
    },
    closeDetail: function(params) {
      this.content = "";
    },
  // 换页刷新
    refreshPageRequest: function(pageNum) {
      this.pageRequest.pageNum = pageNum;
      this.handleDetail();
    },
    // 换页刷新
    handleSizeChange: function(pageSize) {
      this.pageRequest.pageSize = pageSize;
      this.pageRequest.pageNum = 1;
      this.handleDetail();
    },
    selectionChange(data){
      console.log(data);
      this.idArray = data.selections;
    },
    editButton:function(){
      if(this.idArray.length<1){
        this.$message({
            message: '请选择需要操作的数据',
            type: 'error',
            center:true,
            offset:250,
            duration:1000
        });
        return false;
      }
      let params = {'t':'marketAssemble'};
      var this_ = this;
    //   this.utils.request.editUserInfo(params, function(res) {
        this_.$message({
            message: '操作成功',
            type: 'success',
            center:true,
            offset:250,
            duration:1000
        });
        this_.findPage(null);
    //   });
    },
    // 显示编辑界面
    handleDetail: function(params) {
        this.detailParam.t = "marketAssemble";
        this.dialogVisible = true;
        let this_ = this;

        this.utils.request.queryUserList(this.detailParam, function(data) {
            this_.tableData = data.data;
            this_.totalSize = Number(data.data.length); 
        });
    },
    // 时间格式化
    dateFormat: function(row, column, cellValue, index) {
      return format(row[column.property]);
    },

    resetForm(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].resetFields();
        this.findPage(null);
      }
    },

    // 处理表格列过滤显示
    displayFilterColumnsDialog: function() {
      this.$refs.tableColumnFilterDialog.setDialogVisible(true);
    },
    // 处理表格列过滤显示
    handleFilterColumns: function(data) {
      this.filterColumns = data.filterColumns;
      this.$refs.tableColumnFilterDialog.setDialogVisible(false);
    },
    // 处理表格列过滤显示
    initColumns: function() {
      var temp = [];

      $.each(this.columns, function(key, val) {
        temp.push(val);
      });
      this.filterColumns = temp;
    },
    //列表下载
    downloadExcel() {
      this.$confirm("确定下载列表文件?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let filename = "轮播图管理下载";
          this.$refs.CyTable.exportData(
            this.filters,
            this.filterColumns,
            filename
          );
        })
        .catch(() => {});
    }
  },
  mounted() {
    this.initColumns();
  }
};
</script>

<style scoped>
</style>